//
//  LeaderboardFromViewController.m
//  Gxj
//
//  Created by 刘伟 on 2017/9/6.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "LeaderboardFromViewController.h"
#import "WeekViewController.h"
#import "MonthsViewController.h"
#import "TotalViewController.h"
#import "LeaderboardFromView.h"

@interface LeaderboardFromViewController ()<SGPageTitleViewDelegate, SGPageContentViewDelegate>
{
    LeaderboardFromView *_leaderBoardView;
}
@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentView *pageContentView;
@end

@implementation LeaderboardFromViewController

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    //去掉导航栏底部的黑线
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fanhui1"] style:UIBarButtonItemStyleDone target:self action:@selector(clickLeftBarButton)];
    
    self.title = @"排行榜";
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, kWidthScale(20), kHeightScale(20));
    [rightBtn setImage:[UIImage imageNamed:@"shuoming"] forState:0];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;  // 侧滑返回
    
    [self showLeaderblardVC];
    
    [self showBang];
}

- (void)showBang
{
    WeekViewController *childOne = [[WeekViewController alloc] init];
    MonthsViewController *childTwo = [[MonthsViewController alloc] init];
    TotalViewController *childThree = [[TotalViewController alloc] init];
    
    NSArray *childArr = @[childOne, childTwo, childThree];
    
    /// pageContentView
    CGFloat contentViewHeight = self.view.frame.size.height - 180;
    self.pageContentView = [[SGPageContentView alloc] initWithFrame:CGRectMake(0, kHeightScale(180), UIScreenWidth, contentViewHeight) parentVC:self childVCs:childArr];
    _pageContentView.delegatePageContentView = self;
    self.pageContentView.isScrollEnabled = NO;
    [self.view addSubview:_pageContentView];
    
    NSArray *titleArr = @[@"周榜", @"月榜", @"总榜"];
    /// pageTitleView
    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, kHeightScale(149), UIScreenWidth, kHeightScale(31)) delegate:self titleNames:titleArr];
    [self.view addSubview:_pageTitleView];
    _pageTitleView.selectedIndex = 0;
    _pageTitleView.titleColorStateNormal = [UIColor lightGrayColor];
    _pageTitleView.titleColorStateSelected = [UIColor blackColor];
    _pageTitleView.indicatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"fengetiaotwo"]];
    _pageTitleView.indicatorLengthStyle = SGIndicatorLengthStyleEqual;
    _pageTitleView.isShowBottomSeparator = NO;
}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentView setPageCententViewCurrentIndex:selectedIndex];
}

- (void)pageContentView:(SGPageContentView *)pageContentView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}

- (void)clickLeftBarButton
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)showLeaderblardVC
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    _leaderBoardView = [[LeaderboardFromView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(149))];
    [self.view addSubview:_leaderBoardView];
}

@end
